﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using dhDataAcess.baseBLL;
using dhDataAcess.orderLinqDAL;
using dhDataAcess.dataAcess.orderDataSetTableAdapters;
using dhDataAcess.dataAcess;
using System.Data.SqlClient;
using dhDataAcess.orderDAL;


namespace dhSystemBLL.orderData
{
   public  class custAddListBLL
    {
       private custAddListTableAdapter _custAddListadapter = null;
       private custAddListTableAdapter custAddListadapter
       {
           get 
           {
               if (_custAddListadapter == null) _custAddListadapter  = new custAddListTableAdapter();
               return _custAddListadapter ;
           }
       }
        /// <summary>
        /// 查询客户送货地址信息表格
        /// </summary>
        /// <returns></returns>
       public orderDataSet.custAddListDataTable getcustAddListAll()
       {
           try
           {
              return  custAddListadapter.GetDatacustAddListAll();
           }
           catch(Exception ex)
           {
               throw new Exception(ex.Message.ToString());
           }
       }
        /// <summary>
        /// 根据客户编号查询客户地址信息表
        /// </summary>
        /// <param name="groupNum"></param>
        /// <returns></returns>
       public orderDataSet.custAddListDataTable getcustAddListAll(string custNum)
       {
           try
           {
               return custAddListadapter.GetDatacustAddListBycustNum(custNum);
           }
           catch (Exception ex)
           {
               throw new Exception(ex.Message.ToString());
           }
       }
       /// <summary>
       /// 根据客户编号查询客户地址信息表
       /// </summary>
       /// <param name="groupNum"></param>
       /// <returns></returns>
       public orderDataSet.custAddListDataTable getcustAddAll(string custNum)
       {
           try
           {
               return custAddListadapter.GetDataBycustNum (custNum);
           }
           catch (Exception ex)
           {
               throw new Exception(ex.Message.ToString());
           }
       }
        /// <summary>
       /// 插入客户地址信息表
        /// </summary>
        /// <param name="row"></param>
        /// <returns></returns>

       public int custAddListInsert(custAddListModel row)
       {
           int i = 0;
           SqlConnection conn = dataConn.connOpen();
           SqlTransaction tn = null;
           try
           {
               tn = conn.BeginTransaction();
               custAddListDAL custAddList = new custAddListDAL(conn, tn);
               custAddList.custAddListInsert(row);
               tn.Commit();
               return i;

           }
           catch (Exception ex)
           {
               tn.Rollback();
               throw new Exception(ex.Message.ToString());
           }
           finally
           {
               conn.Close();
           }
          
       }
        /// <summary>
       /// 更新客户地址信息表
        /// </summary>
        /// <param name="row"></param>
        /// <returns></returns>

       public int custAddListUpdate(custAddListModel row)
       {
           int i = 0;
           SqlConnection conn = dataConn.connOpen();
           SqlTransaction tn = null;
           try
           {
               tn = conn.BeginTransaction();
               custAddListDAL custAddList = new custAddListDAL(conn, tn);
               custAddList.custAddListUpdate(row);
               tn.Commit();
               return i;


           }
           catch (Exception ex)
           {
               tn.Rollback();
               throw new Exception(ex.Message.ToString());
           }
           finally
           {
               conn.Close();
           }   
       }
        /// <summary>
       ///根据客户编号删除一行客户地址信息表
        /// </summary>
        /// <param name="itemNum"></param>
        /// <returns></returns>

       public int custAddListDel(string custNum)
       {
           int i = 0;
           SqlConnection conn = dataConn.connOpen();
           SqlTransaction tn = null;
           try
           {
               tn = conn.BeginTransaction();
               custAddListDAL custAddList = new custAddListDAL(conn, tn);
               custAddList.custAddListDel(custNum);
               tn.Commit();
               return i;

           }
           catch (Exception ex)
           {
               tn.Rollback();
               throw new Exception(ex.Message.ToString());
              
           }
           finally
           {
               conn.Close();
           }
       }
    }
}
